
using System;
using System.Text;
using NuevoGenNHibernate.CEN.Ebay;
using NHibernate;
using NHibernate.Cfg;
using NHibernate.Criterion;
using NHibernate.Exceptions;
using NuevoGenNHibernate.EN.Ebay;
using NuevoGenNHibernate.Exceptions;

namespace NuevoGenNHibernate.CAD.Ebay
{
public partial class PagoCAD : BasicCAD, IPagoCAD
{
public PagoCAD() : base ()
{
}

public PagoCAD(ISession sessionAux) : base (sessionAux)
{
}



public PagoEN ReadOIDDefault (int id_Pago)
{
        PagoEN pagoEN = null;

        try
        {
                SessionInitializeTransaction ();
                pagoEN = (PagoEN)session.Get (typeof(PagoEN), id_Pago);
                SessionCommit ();
        }

        catch (Exception ex) {
                SessionRollBack ();
                if (ex is NuevoGenNHibernate.Exceptions.ModelException)
                        throw ex;
                throw new NuevoGenNHibernate.Exceptions.DataLayerException ("Error in PagoCAD.", ex);
        }


        finally
        {
                SessionClose ();
        }

        return pagoEN;
}


public int CrearPago (PagoEN pago)
{
        try
        {
                SessionInitializeTransaction ();
                if (pago.Usuario != null) {
                        pago.Usuario = (NuevoGenNHibernate.EN.Ebay.UsuarioEN)session.Load (typeof(NuevoGenNHibernate.EN.Ebay.UsuarioEN), pago.Usuario.Nick);

                        pago.Usuario.Pago.Add (pago);
                }
                if (pago.Venta != null) {
                        pago.Venta = (NuevoGenNHibernate.EN.Ebay.VentaEN)session.Load (typeof(NuevoGenNHibernate.EN.Ebay.VentaEN), pago.Venta.Id_venta);

                        pago.Venta.Pago = pago;
                }

                session.Save (pago);
                SessionCommit ();
        }

        catch (Exception ex) {
                SessionRollBack ();
                if (ex is NuevoGenNHibernate.Exceptions.ModelException)
                        throw ex;
                throw new NuevoGenNHibernate.Exceptions.DataLayerException ("Error in PagoCAD.", ex);
        }


        finally
        {
                SessionClose ();
        }

        return pago.Id_Pago;
}

public PagoEN ReadOID (int id_Pago)
{
        PagoEN pagoEN = null;

        try
        {
                SessionInitializeTransaction ();
                pagoEN = (PagoEN)session.Get (typeof(PagoEN), id_Pago);
                SessionCommit ();
        }

        catch (Exception ex) {
                SessionRollBack ();
                if (ex is NuevoGenNHibernate.Exceptions.ModelException)
                        throw ex;
                throw new NuevoGenNHibernate.Exceptions.DataLayerException ("Error in PagoCAD.", ex);
        }


        finally
        {
                SessionClose ();
        }

        return pagoEN;
}

public System.Collections.Generic.IList<PagoEN> ReadAll (int first, int size)
{
        System.Collections.Generic.IList<PagoEN> result = null;
        try
        {
                SessionInitializeTransaction ();
                if (size > 0)
                        result = session.CreateCriteria (typeof(PagoEN)).
                                 SetFirstResult (first).SetMaxResults (size).List<PagoEN>();
                else
                        result = session.CreateCriteria (typeof(PagoEN)).List<PagoEN>();
                SessionCommit ();
        }

        catch (Exception ex) {
                SessionRollBack ();
                if (ex is NuevoGenNHibernate.Exceptions.ModelException)
                        throw ex;
                throw new NuevoGenNHibernate.Exceptions.DataLayerException ("Error in PagoCAD.", ex);
        }


        finally
        {
                SessionClose ();
        }

        return result;
}
}
}
